package bud.web.boardbud.service;

import java.util.List;

import bud.vo.BoardBudDTO;
import bud.vo.BoardFormDTO;
import bud.vo.ReplyDTO;
import bud.web.boardbud.dao.IBoardbudDao;
import bud.web.boardbud.dao.IReplyDao;

public class BoardbudServiceImpl implements IBoardbudService{

	private IBoardbudDao dao;
	private IReplyDao repDao;
	
	public IBoardbudDao getDao() {
		return dao;
	}
	public void setDao(IBoardbudDao dao) {
		this.dao = dao;
	}
	public IReplyDao getRepDao() {
		return repDao;
	}
	public void setRepDao(IReplyDao repDao) {
		this.repDao = repDao;
	}
	
	@Override
	public List<BoardBudDTO> getBoardbudList(BoardFormDTO formDTO) {
		return dao.getBoardbudList(formDTO);
	}

	@Override
	public int getBoardbudCount(BoardFormDTO formDTO) {
		return dao.getBoardbudCount(formDTO);
	}

	@Override
	public BoardBudDTO getBoardbud(Integer bo_no) {
		return dao.getBoardbud(bo_no);
	}

	@Override
	public BoardbudResult createBoardbud(BoardBudDTO boardbud) {
		int pk = dao.insertBoardbud(boardbud);
		if(pk>0) {
			return BoardbudResult.OK;
		}else {
			return BoardbudResult.FAILED;
		}
	}

	@Override
	public BoardbudResult modifyBoardbud(BoardBudDTO boardbud) {
		BoardBudDTO tempBoardbud = dao.getBoardbud(boardbud.getBo_no());
		if(tempBoardbud==null) {
			return BoardbudResult.FAILED;
		}else {
			if(tempBoardbud.getBo_pass().equals(boardbud.getBo_pass())) {
				int result =dao.updateBoardbud(tempBoardbud);
				if(result>0) {
					return BoardbudResult.OK;
				}else {
					return BoardbudResult.FAILED;
				}
			} else {
				return BoardbudResult.INVALIDPASSWORD;
			}
		} 
	}

	@Override
	public BoardbudResult removeBoardbud(BoardBudDTO boardbud) {
		BoardBudDTO tempBoardbud = dao.getBoardbud(boardbud.getBo_no());
		if(tempBoardbud==null) {
			return BoardbudResult.FAILED;
		}else {
			if(tempBoardbud.getBo_pass().equals(boardbud.getBo_pass())) {
				int result =dao.deleteBoardbud(boardbud.getBo_no());
				if(result>0) {
					return BoardbudResult.OK;
				}else {
					return BoardbudResult.FAILED;
				}
			} else {
				return BoardbudResult.INVALIDPASSWORD;
			}
		} 
	}

	@Override
	public List<ReplyDTO> getRepList(BoardFormDTO form) {
		return repDao.getRepList(form);
	}

	@Override
	public int insertReply(ReplyDTO reply) {
		return repDao.insertReply(reply);
	}

	@Override
	public int deleteReply(ReplyDTO reply) {
		return repDao.deleteReply(reply);
	}

	@Override
	public int getRepCount(Integer rep_ref_key) {
		return repDao.getRepCount(rep_ref_key);
	}
	
}
